﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmDanhSachCanBoNghiHuu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
             ITAPMNS2013Entities context = new ITAPMNS2013Entities();

             System.Data.DataTable dtTK = MakeTable();
             
             foreach(var item in context.GetDSCBCCVCNghiHuu(int.Parse(Request.QueryString["nam"])))
             {
                 System.Data.DataRow row;
                 row = dtTK.NewRow();
                 row["HoTen"] = item.HoTen;
                 //Ngay sinh
                 if (item.NgaySinh == null)
                     row["NgaySinh"] = "";
                 else row["NgaySinh"] = item.NgaySinh.Value.ToShortDateString();
                 //
                 row["NoiSinh"] = item.NoiSinh;
                 row["TenChucVu"] = item.TenChucVu;
                 row["TenPhongBan"] = item.TenPhongBan;
                 row["TenNgachCC"] = item.TenNgachCC;
                 row["MaNgachCC"] = item.MaNgachCC;
                 row["BacLuong"] = item.BacLuong;
                 // Ngay huong luong
                 if (item.NgayHuongLuong == null)
                     row["NgayHuongLuong"] = "";
                 else row["NgayHuongLuong"] = item.NgayHuongLuong.Value.ToShortDateString();
                 dtTK.Rows.Add(row);
                 //So so bhxh
                 row["SoSoBHXH"] = item.SoSoBHXH;
                 // Thoi diem thong bao nghi huu
                 if (item.ThoiDiemThongBaoNghiHuu == null)
                     row["ThoiDiemThongBaoNghiHuu"] = "";
                 else
                     row["ThoiDiemThongBaoNghiHuu"] = item.ThoiDiemThongBaoNghiHuu.Value.ToShortDateString();
                 // Thoi diem nghi huu
                 if (item.ThoiDiemNghiHuu == null)
                     row["ThoiDiemNghiHuu"] = "";
                 else
                     row["ThoiDiemNghiHuu"] = item.ThoiDiemNghiHuu.Value.ToShortDateString();
                 // Noi cu tru khi nghi huu
                 row["NoiCuTruKhiNghiHuu"] = item.NoiCuTruKhiNghiHuu;
                 row["NamBaoCao"] = Request.QueryString["nam"];
                  
             }

            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_DanhSachCanBoNghiHuu.rpt";
            //Loading Report
            rd.Load(strRptPath);
           
            // Setting report data source
            if (dtTK != null && dtTK.GetType().ToString() != "System.String")
                rd.SetDataSource(dtTK);


            CrystalReportViewer1.ReportSource = rd;

        }

        private System.Data.DataTable MakeTable()
        {
            System.Data.DataTable table = new System.Data.DataTable("Table");
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "HoTen";
            column.Caption = "HoTen";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgaySinh";
            column.Caption = "NgaySinh";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NoiSinh";
            column.Caption = "NoiSinh";
            // Add the column to the table.
            table.Columns.Add(column);


            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenChucVu";
            column.Caption = "TenChucVu";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenPhongBan";
            column.Caption = "TenPhongBan";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenNgachCC";
            column.Caption = "TenNgachCC";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "MaNgachCC";
            column.Caption = "MaNgachCC";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "BacLuong";
            column.Caption = "BacLuong";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayHuongLuong";
            column.Caption = "NgayHuongLuong";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "SoSoBHXH";
            column.Caption = "SoSoBHXH";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ThoiDiemThongBaoNghiHuu";
            column.Caption = "ThoiDiemThongBaoNghiHuu";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ThoiDiemNghiHuu";
            column.Caption = "ThoiDiemNghiHuu";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NoiCuTruKhiNghiHuu";
            column.Caption = "NoiCuTruKhiNghiHuu";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NamBaoCao";
            column.Caption = "NamBaoCao";
            // Add the column to the table.
            table.Columns.Add(column);

            return table;
        }
    }
}